(function() {
	module('Balance Tests');

	test('Setup OK', function() {
		ok(true);
	});

	test('Test startup', function() {
		var view = new TestView();
		var controller = new BalanceController(view);

		controller.startup();

		ok(view.controller === controller);
	});

	test('Test startup state', function() {
		var view = new TestView();
		var controller = new BalanceController(view);

		controller.startup();

		equal(view.state.weightsHolder.length, 9);
		equal(view.state.balanceLeftPlate.length, 0);
		equal(view.state.balanceRightPlate.length, 0);

		var holderState = view.state.weightsHolder;
		var countFakes = 0;
		var countNormals = 0;
		for (var i = 0; i < holderState.length; i++) {
			var weight = holderState[i];
			if (weight.weight == 1) {
				countNormals++;
			} else {
				countFakes++;
			}
		}

		equal(countFakes, 1);
		equal(countNormals, 8);
	});

	// test('Test move weight', function() {
	// var view = new TestView();
	// var controller = new BalanceController(view);
	//
	// controller.startup();
	//
	// var fromIndex = 0;
	// var weight = controller.getWeightsHolder().get(fromIndex);
	// var plate = controller.leftPlate();
	//
	// controller.move(weight, plate);
	//
	// });

	function TestView() {
		this.onSolvedCalled = false;
		this.onFailCalled = false;
		this.onResetCalled = false;
	}

	TestView.prototype.init = function(controller) {
		this.controller = controller;
	};

	TestView.prototype.update = function(state) {
		this.state = {};
		this.state.weightsHolder = state.weightsHolder.slice(0);
		this.state.balanceLeftPlate = state.balanceLeftPlate.slice(0);
		this.state.balanceRightPlate = state.balanceRightPlate.slice(0);
	};

	TestView.prototype.onReset = function() {
		this.onResetCalled = true;
	};

	TestView.prototype.onSolved = function() {
		this.onSolvedCalled = true;
	};

	TestView.prototype.onFail = function() {
		this.onFailCalled = true;
	};
}());